<template>
  <div class="count">
    <h3>作者是：{{author}}，大写：{{ upperAuthor }}</h3>
    <h3>当前求和为：{{sum}}，放大10被后：{{ bigSum }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <button @click="jijia(n)">当前和为奇数再加</button>
    <button @click="dengjia(n)">等一等再加</button>
    <button @click="fuwujia">联系服务器再加</button>
  </div>
</template>

<script>
  import { mapGetters, mapState,mapActions } from 'vuex';
  export default {
    name: "Count",
    data() {
      return {
        n:1,
      }
    },
    computed: {
      ...mapState(['author','sum']),

      // mapGetters的第一种写法，对象式
      // ...mapGetters({'daxie':'upperAuthor','dahe':'bigSum'})

      // mapGetters的第二种写法，数组式
      ...mapGetters(['upperAuthor','bigSum']),
    },
    methods: {
      // 点击【+】的回调
      increment() {
        this.$store.commit("JIA", this.n);
      },
      // 点击【-】的回调
      decrement() {
        this.$store.commit("JIAN", this.n);
      },


      // 靠程序员亲自去写一个一个的方法去联系actions（服务员）
      //#region 
      /* // 点击【当前和为奇数再加】的回调
      incrementOdd() {
        this.$store.dispatch("jijia", this.n);
      },
      // 点击【等一等再加】的回调
      incrementWait() {
        this.$store.dispatch("dengjia", this.n);
      },
      // 点击【联系服务器再加】的回调
      incrementServer() {
        this.$store.dispatch("fuwujia");
      } */
      //#endregion
      
      // mapActions的对象写法
      /* ...mapActions({
        incrementOdd:'jijia',
        incrementWait:'dengjia',
        incrementServer:'fuwujia'
      }) */

      ...mapActions(['jijia','dengjia','fuwujia'])
    },
  }
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
}
button {
  margin-left: 10px;
}
</style>